package com.qitmiaojie.service.impl;

import com.qitmiaojie.controller.utils.Result;
import com.qitmiaojie.service.QiniuService;
import com.qitmiaojie.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * @author miaojie
 * @version 1.0
 * @description TODO
 * @date 2023/3/10 20:03
 */
@Service
public class QiniuServiceImpl implements QiniuService {
    @Value("${qiniu.yuming}")
    private String yuming ;


    @Override
    public Result upload(MultipartFile file) {
        String name = UUID.randomUUID().toString() +file.getOriginalFilename();
        try {
            QiniuUtils.upload2Qiniu(file.getBytes(), name);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("上传失败");
        }
        return Result.success(yuming + name);
    }
}
